Random list mechanism
There are many things in the game that follow this mechanism to choose different effects/types randomly such as Golden cookie, Wrath cookie, Force the Hand of Fate, Garden mutations, and Sugar Lump types. Basically the mechanism starts with a pool which contains certain effects. Then it adds different effects to the pool randomly. Finally it chooses one effect from the pool with equal probability. Garden Mutations At each tick, the game will check every empty plots for possible mutation recipes. If certain conditions are satisfiedSome plants will prevent other plants from emerging. For example, if an empty plot is surrounded by 2 Crumbspores and 1 Everdaisy, Doughshrooms will never grow on that plot., there will be a corresponding base chance to add the mutated plant into the candidate pool. The final outcome will be chosen from the candidate pool with equal probability. If the soil is Woodchips, the above procedure will loop 3 times at each tick. For example, if an empty plot is surrounded by 8 Queenbeets, there are 3 possible mutations with an equal base chance of p = 0.1%; Juicy Queenbeet, Duketater and Shriekbulb. The candidate pool has 2^3 = 8 possibilities and can be grouped into four kinds according to the size. All pools in the same group has the same probability to be generated. Among the all eight pools, there are four pools which contain Shriekbulbs: 1, 2 and 1 belong to G1, G2 and G3, respectively. The probability of picking Shriekbulbs in pool Gi will be 1/i. After adding all four pools together, the total probability of picking Shriekbulbs is: P = \frac{p(1-p)^2}{1} + 2 \times \frac{p^2(1-p)}{2} + \frac{p^3}{3} = p-p^2+\frac{p^3}{3} \approx 0.0999\% Since in this case all three mutating plants have the same base chance, the probability of picking Duketaters and Juicy Queenbeets will also be P = p - p^2 + (p^3)/3. Hence the probability of picking nothing is P0 = 1 - 3P. If the soil is Woodchips, the procedure will run three times. The final result will be the plant picked in the last round. If no plant was picked in the last round, the final result will be the plant picked in the second round, and so on. The following table lists all three situations which give Shriekbulb after three rounds. Therefore the total probability of mutating Shriekbulbs after three loops will be: W = P + P \times P_{0} + P \times P_{0}^2 = 3p - 12p^2 + 28p^3 - 42p^4 + 42p^5 - 28p^6 + 12p^7 - 3p^8 + \frac{p^9}{3} \approx 0.2988\% Hence the probability of picking nothing will be: W_{0} = 1-3W = P_{0}^3 = 99.1036\% Take another example, if an empty plot is surrounded by 2 Baker's Wheat, then there are three mutation candidates; Baker's Wheat, Thumbcorn and Bakeberry. These have a base chance of p1 = 20%, p2 = 5% and p3 = 0.1%, respectively. There are 2^3 = 8 possible candidate pools. The probability of picking Baker's Wheat, Thumbcorn, Bakeberry or nothing are: If the soil is Woodchips, the probability of picking Baker's Wheat, Thumbcorn, Bakeberry or nothing are: Force the Hand of Fate The procedure of Force the Hand of Fate is a little different. For golden cookie, the procedure is: Win: *Add Frenzy and Lucky to a pool. *If there is no Dragonflight buff active, add Click Frenzy. *10% chance to add Storm, Storm and Blab to the pool. *25% chance to add Building Special, if the you owned more than or equal to 10 total building. **For all building of which number more or equal to 10, choose one and buff according to the chosen building's amount. If no building has such quantity, choose Frenzy. *15% chance to replace the pool with Storm Drop. *0.01% chance to add Free Sugar Lump to the pool. *Pick a random effect from the list. Note that there is 15% chance for the pool to be replaced completely instead of adding something into the pool. To handle this rule properly, consider two cases. First assume that the pool is never replaced. Second, assume that the pool is always replaced: The actual probability will be mix of these two cases. Fail: *Add Clot and Ruin to a pool. *10% chance to add Cursed Finger, Elder Frenzy to the pool. *0.3% chance to add Free Sugar Lump to the pool. *10% chance to replace the pool with Blab. *Pick a random effect from the list. Golden/Wrath cookie Golden cookie For Golden cookie and Wrath cookie, there is an additional rule. Here is a detailed example for the procedure of picking effect of golden cookies in version 1.0466. For probability of Golden/Wrath cookie in current version, see Golden Cookie Probabilities. *Add Frenzy and Lucky to a pool. *'p1 = 3%' chance to add Chain to the pool, if at least 100,000 cookies have been baked in this game. *'p2 = 10%' chance to add Click Frenzy to the pool. *'Removal Rule': 80% chance to remove the previous effect from the pool, if it's there. *'p3 = 0.01%' chance to add Blab to the pool. *Pick a random effect from the pool. The Removal Rule makes things more complicated but still doable. First we shall ignore the rule, and calculate the probability by listing all possible pools as mentioned above. (From now on we shall assume that at least 100,000 cookies have been baked.) Therefore, the probability of picking Frenzy, Lucky, Chain, Click Frenzy and Blab are: However, due to the Removal Rule, the actual probability depends on the previous cookie. For example, if the previous cookie was Frenzy, there is an 80% chance that we shall apply the following table. From the table, we can calculate the conditional probability: Remember that the actual probability should be a combination of 20% primitive probability and 80% conditional probability: The actual probability of Lucky is the same as Frenzy. For conditional probability of Chain, we shall consider the following table: And the actual probability is: Repeating the process, we can build up the following table. Notice that since we add Blab after applying the Removal Rule, the conditional/actual probability when the previous cookie was blab is the same as the primitive probability. The table above is a transition matrix, the long term (stationary) probability can be found as the eigenvector of the transition matrix with eigenvalue 1. Using this, we can obtain the following table shows the final result. Each cell represents the "combo probability" or "pair probability" of golden cookies. The sum of every possible pair probability is 1. Wrath cookie For wrath cookies, the procedure of determining effect is different: *Add Lucky, Clot and Ruin to a pool. *30% chance to add Elder Frenzy and Chain to the pool. *If previous step fails (70%), 3% chance to add Chain to the pool, if at least 100,000 cookies have been baked this game. *10% chance to add Click Frenzy to the pool. *80% chance to remove the last effect from the pool, if it's there. *0.01% chance to add Blab to the pool. *Pick a random effect from the pool. However, the transition matrix can (assuming at least 100,000 cookies have been baked) still be made: And the long term probability can be calculated: The final table of pair probability then can be obtained: Grandmapocalypse The Grandmapocalypse has four phases: Appeased, Awoken, Displeased, Angered. For the first phase all the cookies will be golden, and for the last phase all cookies will be wrath. In the two middle phases, the probability of wrath cookie is 1/3 and 2/3 respectively. If you clicked every cookies no matter what it is, then the transition matrix of these two phases can be obtained by the linear combination of transition matrix of Appeased phase (pure golden cookie) and transition matrix of Awoken phase (pure wrath cookie). Let us show the golden transition matrix and wrath transition matrix first: Then combine them in G:W=2:1 (Awoken) and G:W=1:2 (Displeased): The final tables of pair probability are presented below: Sugar Lump The method of picking sugar lump type is different from the above methods. The type determination procedure is as follows: *Add Normal to a pool. *If you have upgrades Sucralosia Inutilis, 15% chance to add Bifurcated to the pool, otherwise 10% chance to add Bifurcated to the pool. *0.3% chance to add Golden to the pool. *2% chance to add Caramelized to the pool. *0%, 10%, 20% and 30% to add Meaty to the pool if the game is in Appeased, Awoken, Displeased and Angered phase of Grandmapocalypse respectively. *Pick a random effect from the pool. Unlike the previous examples, the random number 0 < P < 1, which decides whether the candidate should be added into the pool or not, is generated only once through the whole process. In the appeased stage, the outcomes are calculated as such, due to the lack of meaty lumps in this stage: * P_{\text{Golden}} = \frac{P_{G}}{4} * P_{\text{Caramelized}} = \frac{P_{C} - P_{G}}{3} + P_{\text{Golden}} * P_{\text{Bifurcated}} = \frac{P_{B} - P_{C}}{2} + P_{\text{Caramelized}} * P_{\text{Normal}} = (1 - P_{B}) + P_{\text{Bifurcated}} In the awoken stage, the outcomes are calculated as such, due to bifurcated being either equal to or higher than meaty: * P_{\text{Golden}} = \frac{P_{G}}{5} * P_{\text{Caramelized}} = \frac{P_{C} - P_{G}}{4} + P_{\text{Golden}} * P_{\text{Meaty}} = \frac{P_{M} - P_{C}}{3} + P_{\text{Caramelized}} * P_{\text{Bifurcated}} = \frac{P_{B} - P_{M}}{2} + P_{\text{Meaty}} * P_{\text{Normal}} = (1 - P_{B}) + P_{\text{Bifurcated}} In the remaining two stages, the outcomes are calculated as such, due to meaty always being higher than bifurcated: * P_{\text{Golden}} = \frac{P_{G}}{5} * P_{\text{Caramelized}} = \frac{P_{C} - P_{G}}{4} + P_{\text{Golden}} * P_{\text{Bifurcated}} = \frac{P_{B} - P_{C}}{3} + P_{\text{Caramelized}} * P_{\text{Meaty}} = \frac{P_{M} - P_{B}}{2} + P_{\text{Bifurcated}} * P_{\text{Normal}} = (1 - P_{M}) + P_{\text{Meaty}} The results are as follows: If the aura Dragon's Curve is applied, the procedures of adding unusual (non-normal) type in the pool is looped twice. In second runs of the loop, the probability, which decides whether all unusual types should be added into the pool or not, is regenerated. The final results is going to be as follows: Code Given an array of probabilities pi describing the probability that item i''' will be added to the random list. This function returns a new array of probabilities '''Pi describing the overall probability that item i will be picked from the random list. function randomListProb(list) { let out = new Array(list.length).fill(0); for (let i=1; i Example randomListProb(0.5); // 0.375 Notes Category:Utilities Category:Game Mechanics